// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios'
import store from './store';
import Vuex from 'vuex';

Vue.use(Vuex);
Vue.prototype.$axios = axios;
axios.interceptors.request.use(
  (config) => {
    let dlyk_token = localStorage.getItem('dlyk_token');
    if(dlyk_token){
      config.headers['dlyk_token'] = dlyk_token;
    }
    console.log('Request intercepted:', config); // 记录请求配置
    return config; // 必须返回 config，否则请求会被阻止
  },
  (error) => {
    return Promise.reject(error); // 错误处理
  }
);


axios.interceptors.response.use(function (response) {
  // 2xx 范围内的状态码都会触发该函数。
  // 对响应数据做点什么，比如: 数据剥离
  if(response.data.code == 902){
    localStorage.removeItem('dlyk_token');
    router.push('/')
  }
  return response;
}, function (error) {
  // 超出 2xx 范围的状态码都会触发该函数。
  // 对响应错误做点什么: 比如统一处理token失效
  return Promise.reject(error);
});
Vue.config.productionTip = false
Vue.use(ElementUI);
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
